package cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotations.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_level.Nurse_levelDO;
import cn.iocoder.yudao.module.yyzx.service.nurse_level.Nurse_levelService;

@Tag(name = "管理后台 - 护理级别")
@RestController
@RequestMapping("/yyzx/nurse_level")
@Validated
public class Nurse_levelController {

    @Resource
    private Nurse_levelService nurse_levelService;

    @PostMapping("/create")
    @Operation(summary = "创建护理级别")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_level:create')")
    public CommonResult<Integer> createNurse_level(@Valid @RequestBody Nurse_levelSaveReqVO createReqVO) {
        return success(nurse_levelService.createNurse_level(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新护理级别")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_level:update')")
    public CommonResult<Boolean> updateNurse_level(@Valid @RequestBody Nurse_levelSaveReqVO updateReqVO) {
        nurse_levelService.updateNurse_level(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除护理级别")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_level:delete')")
    public CommonResult<Boolean> deleteNurse_level(@RequestParam("id") Integer id) {
        nurse_levelService.deleteNurse_level(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得护理级别")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_level:query')")
    public CommonResult<Nurse_levelRespVO> getNurse_level(@RequestParam("id") Integer id) {
        Nurse_levelDO nurse_level = nurse_levelService.getNurse_level(id);
        return success(BeanUtils.toBean(nurse_level, Nurse_levelRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得护理级别分页")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_level:query')")
    public CommonResult<PageResult<Nurse_levelRespVO>> getNurse_levelPage(@Valid Nurse_levelPageReqVO pageReqVO) {
        PageResult<Nurse_levelDO> pageResult = nurse_levelService.getNurse_levelPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, Nurse_levelRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出护理级别 Excel")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_level:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportNurse_levelExcel(@Valid Nurse_levelPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<Nurse_levelDO> list = nurse_levelService.getNurse_levelPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "护理级别.xls", "数据", Nurse_levelRespVO.class,
                        BeanUtils.toBean(list, Nurse_levelRespVO.class));
    }

}